using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DoAn_LyThuyet.HeThongXuLy;
using DoAn_LyThuyet.HeThongLuuTru;

namespace DoAn_LyThuyet.HeThongGiaoDien
{
    public partial class frmTraCuTaiSan : Form
    {
        public frmTraCuTaiSan()
        {
            InitializeComponent();
        }
        DataAccess ac = new DataAccess ();
        static public DataTable SelectTaiSanAll()
        {

            string sql = "select t.MaTaiSan,t.TenTaiSan, p.TenPhong,pb.NgayPhanBo from TaiSan as t,PhanBoTaiSan as pb, Phong p where t.MaTaiSan = pb.MaTaiSan and p.MaPhong = pb.MaPhong ";
            DataTable dt =  DataAccess.GetTable(sql);           
            return dt;
        }        
       
        private void frmTraCuTaiSan_Load(object sender, EventArgs e)
        {
          dataGridViewdanhsach.DataSource = SelectTaiSanAll();          
        }
        private void ClearControl_TraCu()
        {
            txtnhap.Text = " ";

        }
        private void txtnhap_TextChanged(object sender, EventArgs e)
        {         
           
            if (txtnhap.Text.Length == 0)
                dataGridViewdanhsach.DataSource = SelectTaiSanAll();
            else
            { 
                if(radioButtonMa.Checked)

                    dataGridViewdanhsach.DataSource = DataAccess.GetTable("select t.MaTaiSan,t.TenTaiSan,p.TenPhong, pb.NgayPhanBo from TaiSan as t, PhanBoTaiSan as pb, Phong p where t.MaTaiSan like N'%" + txtnhap.Text + "%' and t.MaTaiSan = pb.MaTaiSan and p.MaPhong = pb.MaPhong");
                else

                    dataGridViewdanhsach.DataSource = DataAccess.GetTable("select t.MaTaiSan,t.TenTaiSan,p.TenPhong, pb.NgayPhanBo from TaiSan as t, PhanBoTaiSan as pb, Phong p where t.TenTaiSan like N'%" + txtnhap.Text + "%' and t.MaTaiSan = pb.MaTaiSan and p.MaPhong = pb.MaPhong");

            }
             
        }

        private void btthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtnhap_MouseClick(object sender, MouseEventArgs e)
        {
            txtnhap.Text = "";
        }
    }
}